
CREATE OR REPLACE FUNCTION registrar_cliente(numerodocumento integer, idtipodocumento integer, nom character varying, ape character varying, dir character varying, tel character varying, mail character varying, pass_word character varying)
  RETURNS boolean AS
$BODY$

DECLARE

resultado boolean;
registro_encontrado integer;

BEGIN

registro_encontrado := 0;

SELECT  count(*) into registro_encontrado from cliente c where c.numero_documento = numeroDocumento;

if(registro_encontrado > 0) then 
	resultado := false;
else
	insert into cliente values (default,numeroDocumento,idTipoDocumento,nom,ape,dir,tel,mail,pass_word,true);
	resultado := true;
end if;

return resultado;

END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION registrar_cliente(integer, integer, character varying, character varying, character varying, character varying, character varying, character varying)
  OWNER TO postgres;